package uf.tax.laws.spider.gs;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import uf.tax.laws.spider.HttpDAO;

public class GetLawItem {
	HttpDAO dao;
	String url, title, content;

	public GetLawItem(HttpDAO dao, String url) {
		this.url = url;
		this.dao = dao;
	}

	Pattern p = Pattern.compile("<b><span style=\"font-size: medium\">(.*?)</span></b>", Pattern.DOTALL);

	private void processItem() {
		content = dao.get("http://hd.chinatax.gov.cn/guoshui" + url);
		Matcher m = p.matcher(content);
		if (m.find()) {
			title = m.group(1).trim();
		} else {
			System.out.println("TITLE NOT FOUND: http://hd.chinatax.gov.cn/guoshui" + url);
			System.out.println(content);
		}
	}

	public String getContent() {
		if (content == null) {
			processItem();
		}
		return content;
	}

	public String getTitle() {
		if (title == null) {
			processItem();
		}
		return title;
	}
}
